<?php
namespace app\controller;

use think\Request;
use app\common\UtilService;
use app\model\Ip as IpModel;

class Ip extends Base
{
    /**
     * [index 首页]
     * @since  2022-03-18
     * @author Dai哥
     * @return [type]     [description]
     */
    public function index()
    {
        $ipCount = IpModel::count();

        $todayCount = IpModel::whereDay('create_time')->count();

        # 共几页
        $pageTotal = ceil($ipCount/10);

        return view('index', compact('ipCount', 'todayCount', 'pageTotal'));
    }

    /**
     * [ipList 异步获取IP列表]
     * @since  2022-03-31
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function ipList(Request $request)
    {
        try {

            $param = UtilService::getMore([
                ['page', 1],
                ['limit', 10],
            ]);

            $list = IpModel::getIpList($param);

            return success($list, 'ok');
            
        } catch (\Exception $e) {

            // 这是进行异常捕获
            return error($e->getMessage());
        }
    }
}